package com.fu.edu.manager.service;

import com.fu.edu.manager.dao.TeacherDao;
import com.fu.edu.manager.domain.Teacher;

/**
 * @author 付大大
 * @create 2021-01-06 17:24
 */
public class TeacherService {
    private TeacherDao teachDao = new TeacherDao();

    public boolean addTeacher(Teacher teacher) {
        return teachDao.addTeacher(teacher);
    }

    public boolean isExists(String id) {
        Teacher[] teachers = teachDao.findAllTeacher();
        boolean exists = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null && teacher.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teachDao.findAllTeacher();
        boolean flag = false;

        for (int i = 0; i < allTeacher.length; i++) {
            Teacher teacher = allTeacher[i];
            if (teacher != null) {
                flag = true;
                break;
            }
        }

        if (flag) {
            return allTeacher;
        } else {
            return null;
        }
    }

    public void deleteTeacherById(String id) {
        teachDao.deleteTeacherById(id);
    }

    public void updateTeacher(String id, Teacher teacher) {
        teachDao.updateTeacher(id, teacher);
    }
}
